open BUFF,"hapmap3.tped.fws.norm_new.tped" or die "no hapmap files exists\n";
$n = 0;
while(<BUFF>)
{
	if($_ =~ m/^23/)
	{
		@array = split(" ",$_);
		$l = "";
		if($_ =~ m/A/)
		{
			$l = $l."A";
		}
		if($_ =~ m/C/)
                {
                        $l = $l."C";
                }
		if($_ =~ m/G/)
                {
                        $l = $l."G";
                }
		if($_ =~ m/T/)
                {
                        $l = $l."T";
                }
		$hash{$array[1]} = $l;
		 #print "$array[1] $hash{$array[1]}\n";
		$n++;
	}
}
print "$n\n";
open BUFF,"./untouch_xchrimputationfiles/markers.txt" or die "no markers.txt file exists\n";
open BUFF1,"./untouch_xchrimputationfiles/phasedfemale.bgl" or die "no phasedfemale.bgl files exists\n";
open BUFF2,"./untouch_xchrimputationfiles/phasedmale.bgl" or die "no phasedmale.bgl files exists\n";
open(WRBUFF,">markers_new.txt");
open(WRBUFF1,">phasedfemale_new.bgl");
open(WRBUFF2,">phasedmale_new.bgl");
$line = <BUFF1>;
print WRBUFF1 $line;
$line = <BUFF2>;
print WRBUFF2 $line;
#print $line."\n";
while(<BUFF>)
{
	$male = <BUFF2>;
	$female = <BUFF1>;
	#print "$male\n$female\n";
	$male_female = $male.$female;
	@male = split(" ",$male);
	@female = split(" ",$female);
	@array = split(" ",$_);
	#print "test $array[0] $hash{$array[0]}\n";
	if(exists($hash{$array[0]}))
	{
		 $l = "";
                if($male_female =~ m/A/)
                {
                        $l = $l."A";
                }
                if($male_female =~ m/C/)
                {
                        $l = $l."C";
                }
                if($male_female =~ m/G/)
                {
                        $l = $l."G";
                }
                if($male_female =~ m/T/)
                {
                        $l = $l."T";
                }
		@l = split('',$l);
		@l = sort(@l);
		$l = join("",@l);
		@l = split('',$hash{$array[0]});
		@l = sort(@l);
		$hash{$array[0]} = join("",@l);
		$m = $l;
		$m =~ tr/ACGT/TGCA/;
		@l = split('',$m);
		@l = sort(@l);
		$m = join("",@l);
		if($l eq $hash{$array[0]})
		{
			print WRBUFF $_;
			print WRBUFF2 $male;
			print WRBUFF1 $female;
		}
		elsif($m eq $hash{$array[0]})
		{	
			$_ =~ tr/ACGT/TGCA/;
			$male =~ tr/ACGT/TGCA/;
			$female =~ tr/ACGT/TGCA/;
			print WRBUFF $_;
                        print WRBUFF2 $male;
                        print WRBUFF1 $female;
		}
		else
		{
			die "$array[0]\t$l\t$m\t$hash{$array[0]}\n";
		}
	}
}
close(WRBUFF);
close(WRBUFF1);
close(WRBUFF2);
